package org.lboot.llog.module;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.lboot.jpa.entity.NoAuditLongBaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

/**
 * @author kindear
 * 日志服务
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = "api_log")
@ApiModel(value = "接口请求日志",description = "接口请求日志记录实体类")
public class ApiLogEntity extends NoAuditLongBaseEntity implements Serializable {

    @ApiModelProperty(value = "追踪ID")
    @Column(name = "trace_id")
    String traceId;

    @ApiModelProperty(value = "服务名称",example = "鉴权服务")
    @Column(name = "service_name")
    String serviceName;

    @ApiModelProperty(value = "服务地址",example = "服务地址")
    @Column(name = "service_host")
    String serviceHost;

    @ApiModelProperty("功能模块")
    @Column(name = "module")
    String module;

    @ApiModelProperty("接口名称")
    @Column(name = "api_name")
    String apiName;

    @ApiModelProperty("方法名")
    @Column(name = "method")
    String method;

    @ApiModelProperty("方法类路径")
    @Column(name = "clazz")
    String clazz;

    @ApiModelProperty("请求参数")
    @Column(name = "params",columnDefinition = "TEXT")
    String params;

    @ApiModelProperty("返回数据")
    @Column(name = "return_data",columnDefinition = "TEXT")
    String returnData;

    @ApiModelProperty("操作")
    @Column(name = "action")
    String action;


    // 执行失败设置为 0
    @ApiModelProperty("请求状态")
    @Column(name = "status")
    Integer status;


    @ApiModelProperty("操作用户ID")
    @Column(name = "operator_id")
    String operatorId;


    @ApiModelProperty("客户端请求IP")
    @Column(name = "client_ip")
    String clientIp;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "操作开始时间",name = "startTime")
    @Column(name = "start_time")
    private Date startTime;


    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "操作结束时间",name = "endTime")
    @Column(name = "end_time")
    private Date endTime;


    @ApiModelProperty("耗费时长")
    @Column(name = "total_time")
    private Integer totalTime;
}
